package com.ali.Reggie.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：ALi
 * @date ：Created in 2022/6/6 16:10
 * @description：返回结果类
 * @modified By：
 * @version: $
 */
@Data
public class R<T>{
    private Integer code; //编码：1成功，0和其它数字为失败

    private String msg; //错误信息

    private T data; //数据

    private Map map = new HashMap(); //动态数据

    public static <T> R<T> success(T object) {
        R<T> res = new R<T>();
        res.data = object;
        res.code = 1;
        return res;
    }


    public static <T> R<T> error(String msg) {
        R res = new R();
        res.msg = msg;
        res.code = 0;
        return res;
    }

    public R<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }

}